package com.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.domain.ChatUser;
import com.example.service.ChatUserService;
import com.example.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 不是菜鸡爱编程
 * @Date: 2024/01/29/19:37
 * @Description:
 */
@RestController
@RequestMapping("user")
public class ChatUserController {
    @Autowired
    private ChatUserService chatUserService;

    /**
     * 登录
     *
     * @param chatUser 用户聊天
     * @return {@link R}
     */
    @PostMapping("/login")
    public R login(@RequestBody ChatUser chatUser) {
        return chatUserService.login(chatUser.getUsername(), chatUser.getPassword());
    }

    /**
     * 获取用户
     *
     * @param id id
     * @return {@link R}
     */
    @GetMapping("/{id}")
    public R getUser(@PathVariable Integer id) {
        ChatUser one = chatUserService.getOne(new LambdaQueryWrapper<ChatUser>()
                .eq(ChatUser::getId, id));
        return R.ok().setData(one);
    }
}
